package com.cosc716.restaurant.commands.menu;

import java.util.Iterator;

import com.cosc716.restaurant.commands.Command;
import com.cosc716.restaurant.domain.Menu;
import com.cosc716.restaurant.domain.MenuItem;
import com.cosc716.restaurant.system.Aggregator;

public class CommandDeleteMenuItem implements Command {
	
	private MenuItem deleteItem = null;
	
	public CommandDeleteMenuItem(MenuItem deleteItem) {
		this.deleteItem = deleteItem;
	}

	@Override
	public Object execute(Aggregator aggregator) {
		
		if(deleteItem != null) {		    
			// Get the menu to delete it from
			Menu menu = aggregator.getMenu();
			
			// Look through the menu and remove all items that match that name
			Iterator<MenuItem> menuItemIterator = 
					menu.getMenuItemMenuIterator(deleteItem);
			while(menuItemIterator.hasNext()) {
				menuItemIterator.remove();
			}
			
			return true;
		}
		
		return false;
	}

}